#include <bits/stdc++.h>
using namespace std;

const int N=305;
int n,a[N],f[N][N][N];

int main(){
  freopen("build.in","r",stdin);
  freopen("build.out","w",stdout);
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];

  for(int len=1;len<=n;len++)
    for(int l=1,r=len;r<=n;l++,r++)
	  for(int x=1,y=len;y<=n;x++,y++)
	    f[l][r][x]=min(min(f[l+1][r][x+1]+(a[l]!=x),f[l+1][r][x]+(a[l]!=y)),min(f[l][r-1][x+1]+(a[r]!=x),f[l][r-1][x]+(a[r]!=y)));
  cout<<f[1][n][1];
  return 0;
}